package com.zy.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.zy.mapper.CustomerMapper;
import com.zy.pojo.Customer;
import com.zy.service.CustomerService;
import com.zy.vo.CustomerVo;
import com.zy.vo.custvo.PageCto;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

;

@Service("customerService")
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> implements CustomerService {

    @Resource
    private CustomerMapper customerMapper;

    @Override
    public PageCto getPage(Integer pageNo, Integer pageSize, CustomerVo customerVo) {
        Page page = new Page();
        page.setSize(pageSize);
        page.setCurrent(pageNo);
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.like(!StringUtils.isEmpty(customerVo.getCustomerName()),"supper_Name",customerVo.getCustomerName());

        List<Customer> list = customerMapper.getCustomerList(page,queryWrapper);
        System.out.println(page.getTotal()+"+++++++++++++++++++++++++");
        return new PageCto(list,page.getTotal());
    }

    @Override
    public void getcustomeradd(Customer customer) { customerMapper.insert(customer); }

    @Override
    public void getcustomerdel(Integer id) { customerMapper.deleteById(id); }

    @Override
    public void getcustomerupdate(Customer customer) { customerMapper.updateById(customer); }
}
